package com.lh.util;

import org.apache.commons.codec.binary.Base64;

import java.io.*;

/**
 * @Author: LuoHang
 * @Date: 2021/2/12 11:26
 * @Description
 */

public class Base64Tool {
    public static String getBase64FromInputStream(String path) {
        File file = new File(path);
        InputStream is;
        byte[] imageBytes = null;
        int res = 0;
        try {
            is = new FileInputStream(file);
            imageBytes = new byte[(int) file.length()];
            res = is.read(imageBytes, 0, imageBytes.length);
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return res > 0 ? Base64.encodeBase64String(imageBytes) : "";
    }
}
